package com.lin.cms.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.lin.cms.domain.User;

public class UserValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return User.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "registerTime", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "registerIp", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastLoginTime", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastLoginIp", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginCount", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "errorCount", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "activation", "required");
	}

}
